#include <QtGui>
#include <QtCore/QTextCodec>
#include <QTranslator>
#include "gv_setuplanguagedialog.h"
#include "gv_setuphomedialog.h"
#include "gv_home.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
GV_SetupLanguageDialog::GV_SetupLanguageDialog(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(GV_chTime()));
    connect(BackButton,SIGNAL(clicked()),this,SLOT(setuphome()));
    connect(CancelButton,SIGNAL(clicked()),this,SLOT(setuphome()));
    connect(AcceptButton,SIGNAL(clicked()),this,SLOT(setuphome()));
    timer->start(1000);
}

void GV_SetupLanguageDialog::GV_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}

void GV_SetupLanguageDialog::reloadtext()
{
    NameHintseLabel->setText(tr("User's Setup"));
    BackButton->setText(tr("Back"));
    AcceptButton->setText(tr("Accept"));
    CancelButton->setText(tr("Cancel"));

    LanguageSetupLanguageGroupBox->setTitle(tr("Language"));
}

void GV_SetupLanguageDialog::setuphome()
{
    QString lan("ENGLISH");
    if(ChineseSetupLanguageRadio->isChecked())
    {
        lan = "CHINESE";
    }else if(EnglishSetupLanguageRadio->isChecked()){
        lan = "ENGLISH";
    }else if(DutchSetupLanguageRadio->isChecked()){
        lan = "DUTCH";
    }else if(GermanSetupLanguageRadio->isChecked()){
        lan = "GERMAN";
    }else if(FrenchSetupLanguageRadio->isChecked()){
        lan = "FRENCH";
    }
    //QMessageBox::about(this,"Language",lan + QString(":") + gvsetting->GV_GetLanguageName());
    if(lan != gvsetting->GV_GetLanguageName())
    {
        gvsetting->GV_SetLanguage(lan);
    }
    //QMessageBox::about(this,"Now Language",gvsetting->GV_GetLanguageName());

    QDialog *dialog1 = new GV_SetupHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

